//
//  BaikeViewController.m
//  A段
//
//  Created by 月月 on 15/4/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "BaikeViewController.h"
#import "Baike1ViewController.h"
#import "Baike2ViewController.h"

@interface BaikeViewController ()<UITableViewDelegate, UITableViewDataSource>

{
    UITableView *_table;
}
@property(nonatomic, retain)NSMutableArray *tableArray;

@end

@implementation BaikeViewController

- (void)dealloc
{
    [_tableArray release];
    [super dealloc];
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];
        
        NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
        [dic1 setObject:@"什么是陀飞轮？" forKey:@"name"];
        [dic1 setObject:@"May 20, 2013" forKey:@"date"];
        
        NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
        [dic2 setObject:@"机械表该如何保养？" forKey:@"name"];
        [dic2 setObject:@"May 20, 2013" forKey:@"date"];
        
        [self.tableArray addObject:dic1];
        [self.tableArray addObject:dic2];
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self createTable];
    
    
}


-(void)createTable{
    
    _table = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain] autorelease];
    _table.delegate = self;
    _table.dataSource = self;
    [self.view addSubview:_table];
    _table.rowHeight = 120;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.tableArray count ];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cells = @"ss";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cells];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cells] autorelease];
    }
    NSDictionary *dic =[NSDictionary dictionary];
    dic = [self.tableArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [dic objectForKey:@"name"];
    cell.detailTextLabel.text = [dic objectForKey:@"date"];
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // 取消选中状态
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row  == 0 ) {
        Baike1ViewController *bai1 = [[[Baike1ViewController alloc] init] autorelease];
        [self.navigationController pushViewController:bai1 animated:YES];
    } if (indexPath.row == 1) {
        Baike2ViewController *bai2 = [[[Baike2ViewController alloc] init] autorelease];
        [self.navigationController pushViewController: bai2 animated:YES];
    }
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
